import request from '@/utils/request';
import store from '@/store';

export function getAccountInfoByToken(data) {//账号 返回账号信息 通过Token
  return request({
    url: '/User/GetAccountInfoByToken',
    method: 'get',
    data
  });
}
export function getRoleListKeyInfo(data) {//取角色列表
  return request({
    url: '/User/GetRoleListKeyInfo',
    method: 'get',
    data
  });
}

export function getRightItemAll(data) {//取权限项
  return request({
    url: '/User/GetRightItemAll',
    method: 'get',
    data
  });
}

export function getRightIDListByRole(data) {//取权限ID值 通过roleid
  return request({
    url: '/User/GetRightIDListByRole?roleid='+data,
    method: 'get',
    data,
  });
}
export function getRightCodeListByToken() {//取权限code值
  return request({
    url: '/User/GetRightCodeListByToken',
    method: 'get',
  });
}

export function saveUserRight(data) {//保存角色权限值
  return request({
    url: '/User/SaveUserRight',
    method: 'post',
    data,
  });
}


function getGwRightItem(data) {//取顾问权限角色的有效权限编号
  return request({
    url: '/SystemManage/GetGwRightItem',
    method: 'post',
    data
  });
}

function getGwRightItemCode(data) {//取顾问权限角色的有效权限编码
  return request({
    url: '/SystemManage/GetGwRightItemCode',
    method: 'post',
    data
  });
}

export async function getRightItem(righitem) {//取顾问当前窗口权限的有效权限编号
  let r='';
  let datapara={
    gwgroupid:store.getters.gwgroupid,
    gwrightitem:righitem,
  }; 
  await getGwRightItem(datapara).then( m => {
    if(m.errcode == 0){ 
      r=m.data;
    }
  });
  return r;
}

export async function SetRightCode(righitemcode) { //顾问当前窗口权限的有效权限编码
  let rightcode=righitemcode;
  let code='';
  let getcode='';
  for (var item in rightcode){
    if(code!=''){code=code+',';}
    code=code+'\''+ item +'\'';
  }
  let datapara={
    gwgroupid:store.getters.gwgroupid,
    gwrightitemcode:code,
  };
  await getGwRightItemCode(datapara).then( m => {
    if(m.errcode == 0){ 
      getcode=m.data;
    }
  });

  for (var item in rightcode){
    if(getcode.indexOf(item)>0){
      rightcode[item]=true;
    }
  }
  return rightcode;
}

export async function getRightItemCode(righitemcode) {//取
  let r='';
  let datapara={
    gwgroupid:store.getters.gwgroupid,
    gwrightitemcode:righitemcode,
  }; 
  await getGwRightItemCode(datapara).then( m => {
    if(m.errcode == 0){ 
      r=m.data;
    }
  });
  return r; 
}

export function getTreeData(isShowCnt) {//取角色列表  
  return request({
    url: '/SystemManage/GetRoleTreeData?isShowCnt='+(typeof(isShowCnt)=='boolean'?isShowCnt:false),
    method: 'get'
  });
}
export function getTreeDataForGw() {//取角色列表(用于顾问管理-按角色)
  return request({
    url: '/SystemManage/GetRoleTreeDataForGw',
    method: 'get'
  });
}
export function getAddReadyData() {//取角色添加前的准备数据
  return request({
    url: '/SystemManage/GetRoleAddReadyData',
    method: 'get',
  });
}

export function updatedata(data) {//取角色修改前的准备数据
  return request({
    url: '/SystemManage/GetGroupNamelist?id='+data,
    method: 'get',
  });
}

export function saveCompany(data) {//添加和修改角色
  return request({
    url: '/SystemManage/addRoleTree',
    method: 'post',
    data
  });
}
export function deletePuWorkDay (data) {//删除
  return request({
    url: '/SystemManage/DRoleTree?id='+data,
    method: 'get',
    data
  });
}
export function recommended (data) {//基本权限
  return request({
    url: '/SystemManage/Getpermissions',
    method: 'post',
    data
  });
}




export function savepermissions(data) {//保存权限
  return request({
    url: '/SystemManage/Permissions',
    method: 'post',
    data
  });
}

export function Accesspermissions (data) {//获取基本列表
  return request({
    url: '/SystemManage/permissionsList?id='+data,
    method: 'get',
  });
}

export function other (data) {//获取其他权限列表
  return request({
    url: '/SystemManage/Otherrights?id='+data,
    method: 'get',
  });
}

export function delRole (data) {//删除空角色及其权限
  return request({
    url: '/SystemManage/DelRole',
    method: 'post',
    data
  });
}





export function getMyRightList (data) {//获取我的权限列表
  return request({
    url: '/SystemManage/GetMyRightList?gwGroupID='+data,
    method: 'get',
  });
}


